$(function(){
	
	//勾选复选框
	$('.check').on('click',function(){
		if($(this).children('input:checked')){
			$(this).parent().css({background:'#FDF2D8'});	
		}else{
			$(this).parent().css({background:'#FFFFFF'})
		}		
	})
	
		var index = parseInt($('.number').find('span').text());	
		var single_price =parseInt($('.price').find('span').text());
	//减数量	
	$('.decrease').on('click',function(){
		console.log(single_price)
		if(index == 1){
			index = 1;
		}else{
			index--;
		}
	
		//数量框件数
		$('.number').find('span').text(index);
		//已选商品总件数
		$('.num').text(index);
		//金额
		$('.pay_price span').text(single_price*index);	
		//支付的总金额
		$('.total').text(single_price*index)

	});
	//加数量
	$('.add').on('click',function(){	
		if(index < 1){
			index = 1;
		}else{
			index++;
		}
	
		//数量框件数
		$('.number').find('span').text(index);
		//已选商品总件数
		$('.num').text(index);
		//金额
		$('.pay_price span').text(single_price*index);	
		//支付的总金额
		$('.total').text(single_price*index)
	});
	
	
	
	//单个商品的删除
	$('.delete').on('click',function(){
		$(this).parent().parent().remove();
	})
	
	//字符串的拼接
	//var obj = JSON.parse($.cookie('json1'));
		var a = {};
		a = getCookie('obj');
		var value = JSON.parse(a);

		//console.log(JSON.parse(a)[0].goodsImg);
		
		var str = '<tr class="car_goods"><td class="check"><input type="checkbox" name="" id="" value="" /></td>';
		str +='<td class="detail_way"><a href="#"><img src=" '+value[0].goodsImg+'"/>'+value[0].goodsName+'</a><br/>配送方式:'+value[0].time1+'&nbsp;&nbsp;'+value[0].time1+'</td>';
		str += '<td class="price">￥<span>'+value[0].goodsPrice+'</span></td>';
		str += '<td class="counts"><ul><li class="decrease">-</li><li class="number"><span>'+value[0].numb+'</span></li><li class="add">+</li></ul></td>';
		str += '<td class="pay_price">￥<span>'+value[0].goodsPrice*value[0].numb+'</span></td>';
		str += '<td class="delete">删除</td></tr>';
		
		$('table').append(str);

});
